<?php

class Controller_Leadreport extends Controller_Admin
{
    public $defs = array();
    public function before()
    {
        try {
            ACL::Required('leadreport');
        } catch ( HTTP_Exception_403 $e ) {
            Message::error('sorry，你没有权限进这个目录');
            $this->request->redirect ( URL::base (true) );
        }

        parent::before();
    }

    /**
     * 描述 : 展示供应商页面
     * 作者 : Edgar.lee
     */
    public function action_index()
    {
        $this->title = __("供应商SKU交期报表");
        $view        = View::factory("leadreport");

        if(isset($_GET['supplier'])){ //分页查询
            $sql   = $this->getSelSql($_GET);
            $count = $this->request->param('id',FALSE);

            if($count===FALSE){ //查询总长度
                $count = DB::query(Database::SELECT,'SELECT COUNT(`id`) c '.substr($sql,84))
                    ->execute('newerp')
                    ->get('c',0);
            }

            empty($_GET['page'])&&$_GET['page'] = 1;
            $_GET['page'] -= 1;
            $sql .= ' LIMIT '.($_GET['page']*50).', 50';
            $view->set('dataList', //数据列表
                DB::query(Database::SELECT,$sql)
                    ->execute('newerp')
                    ->as_array());

            $pagination = Pagination::factory(array(
                'items_per_page' => 50,
                'total_items'    => $count,
                'uri'            => '/leadreport/index/'.$count,
            ));
            $view->set('pagination',$pagination); //分页列表
        }

        $this->response->body($view);
    }

    /**
     * 描述 : 保存csv报表
     * 作者 : Edgar.lee
     */
    public function action_buildCsv()
    {
        set_time_limit(0);
        $md5      = md5(join('::',$_POST));
        $path     = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$md5.'.csv';
        $cacheSku = array();
        $cacheSu  = array();

        if(!is_file($path)||date('Y-m-d',$_SERVER['REQUEST_TIME'])!==date('Y-m-d',filemtime($path))){ //缓存失效
            $fp = fopen($path,'a+');
            flock($fp,LOCK_EX); //加独享锁
            ftruncate($fp,0); //清空文件内容

            fwrite($fp,iconv('UTF-8','GB18030//IGNORE','sku,商品名,供应商,交期')."\r\n");

            $sql = $this->getSelSql($_POST);
            while(tool::eachSql($sql,$data)){
                $skus = $sus = array(); //初始化数组
                foreach($data as &$v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    isset($cacheSku[$v['sku']])||$skus[$v['sku']] = & $v['sku'];
                    isset($cacheSu[$v['su_id']])||$sus[$v['su_id']] = & $v['su_id'];
                }
                if($temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$skus).'")'),TRUE)){ //无可奈何的写法
                    foreach($temp as &$v){
                        $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                        $cacheSku[$v['sku']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                if($temp = newerpclientapi::getSuppliernameBatch($sus)){ //亲,系统好好设计下呗
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                foreach($data as &$v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    $v['ldt_sec'] = iconv('UTF-8','GB18030//IGNORE',$v['ldt_sec']);
                    $temp         = "{$v['sku']},\"{$cacheSku[$v['sku']]}\"\t,\"{$v['su_id']}::{$cacheSu[$v['su_id']]}\"\t,\"{$v['ldt_sec']}\"\t\r\n";
                    fwrite($fp,$temp);
                }
            }

            fclose($fp);
        }

        echo $md5;
    }

    /**
     * 描述 : 下载csv
     * 作者 : Edgar.lee
     */
    public function action_downLoad()
    {
        set_time_limit(0);
        header('Content-Type: application/download'); //下载头
        header('Content-Transfer-Encoding: binary'); //二进制
        header('Content-Disposition: attachment; filename='.iconv('UTF-8','GB18030//IGNORE','交期报表').'.csv'); //文件名
        header('Pragma:no-cache'); //不缓存

        $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$_GET['md5'].'.csv';
        $fp   = fopen($path,'r');
        flock($fp,LOCK_SH); //加共享锁
        while(!feof($fp)){ //读取数据
            echo fread($fp,8192);
        }
        fclose($fp);

        exit;
    }

    /**
     * 描述 : 供应商报表分页
     * 作者 : Edgar.lee
     */
    private function getSelSql($patams)
    {
        tool::slashesDeep($patams);
        $patams['supplier'] = trim($patams['supplier']);
        $patams['skuName']  = trim($patams['skuName']);
        $patams['userName'] = trim($patams['userName']);
        $sql                = "SELECT
            `sku`, `su_id`, TRUNCATE(`ldt_sec` / 86400, 2) `ldt_sec`
        FROM
            `ldt_ord`
        WHERE
            TRUE";

        if(!empty($patams['supplier'])){ //供应商
            $temp = Newerpclientapi::getSuppliers(array('id'),array('name' => "like '%{$patams['supplier']}%'"));
            foreach($temp as &$v){
                $v = $v['id'];
            }
            $temp = '("'.join('", "',$temp).'")';
            $sql .= ' AND `su_id` IN '.$temp;
        }

        if(!empty($patams['skuName'])){ //sku
            $sql .= " AND `sku` = '{$patams['skuName']}'";
            unset($patams['userName']); //删除负责人
        }

        if(!empty($patams['userName'])){ //负责人
            $temp = Skusystemapi::getUserAllSkuByNick($patams['userName']);
            if(empty($temp)){
                $sql .= ' AND `id` = 0 ';
            }else{
                foreach($temp as &$v){
                    $v = $v['sku'];
                } //转换负责人sku数组

                $temp = '("'.join('", "',$temp).'")';
                $sql .= ' AND `sku` IN '.$temp;
            }
        }

        return $sql;
    }

    /**
     * ft:交期报表
     */
    public function action_highcharts()
    {
        if(isset($_GET)){
            $sku     = $_GET['sku'];
            $su_id   = $_GET['su_id'];
            $res     = DB::select()
                ->from('ldt_base')
                ->where('sku','=',$sku)
                ->where('su_id','=',$su_id)
                ->order_by('put_sec')
                ->execute('newerp')
                ->as_array();
            $put_sec = array();
            $ldt_sec = array();
            foreach($res as $k => $v){
                $put_sec[$k] = date('Y-m-d H:i:s',$v['put_sec']);
                $ldt_sec[$k] = round($v['ldt_sec']/86400,2);
            }
            $view = View::factory('highcharts')
                ->set('sku',$sku)
                ->set('su_id',$su_id)
                ->set('put_sec',$put_sec)
                ->set('ldt_sec',$ldt_sec)
                ->render();
            $json = array('view' => $view);
            echo json_encode($json);
            exit;
        }
    }

    private function getskuSelSql($patams)
    {
        tool::slashesDeep($patams);
        $patams['skuName']  = trim($patams['skuName']);

        //判断是否有人工定义的交期
        $sql = "SELECT `sku`, `su_id`, round(`def_sec`/86400,1) ldt_sec FROM ldt_ord WHERE `def_sec` != 0";
        $this->defs = DB::query(Database::SELECT, $sql)->execute('newerp')->as_array();

        $sql                = "SELECT
            `sku`, `su_id`, round(max(`ldt_sec`)/86400,1) `ldt_sec`
        FROM
            `ldt_ord`
        WHERE
            `su_id`<> 0";

        if(!empty($this->defs)) {
            $sku_str = '';
            foreach($this->defs as $def) {
                $sku_str .= $sku_str!=""?",'".$def['sku']."'":"'".$def['sku']."'";
            }
            $sql .= " AND `sku` NOT IN ({$sku_str})";
        }

        if(!empty($patams['skuName'])){ //sku
            $sql .= " AND `sku` = '{$patams['skuName']}'";
            unset($patams['userName']); //删除负责人
        }

        $sql .= " group by `sku`";

        return $sql;
    }

    public function action_sku_buildCsv()
    {
        set_time_limit(0);
        $_POST['type'] = 1;
        $md5      = md5(join('::',$_POST));
        $path     = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$md5.'.csv';
        $cacheSku = array();
        $cacheSu  = array();
        if(!is_file($path)||date('Y-m-d',$_SERVER['REQUEST_TIME'])!==date('Y-m-d',filemtime($path))){ //缓存失效
            $fp = fopen($path,'a+');
            flock($fp,LOCK_EX); //加独享锁
            ftruncate($fp,0); //清空文件内容

            fwrite($fp,iconv('UTF-8','GB18030//IGNORE','sku,商品名,供应商,最大交期')."\r\n");

            $sql = $this->getskuSelSql($_POST);
            while(tool::eachSql($sql,$data)){
                $skus = $sus = array(); //初始化数组
                foreach($data as &$v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    isset($cacheSku[$v['sku']])||$skus[$v['sku']] = & $v['sku'];
                    isset($cacheSu[$v['su_id']])||$sus[$v['su_id']] = & $v['su_id'];
                }
                if($temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$skus).'")'),TRUE)){ //无可奈何的写法
                    foreach($temp as &$v){
                        $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                        $cacheSku[$v['sku']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                if($temp = newerpclientapi::getSuppliernameBatch($sus)){ //亲,系统好好设计下呗
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                foreach($data as &$v){
                    $v['ldt_sec'] = iconv('UTF-8','GB18030//IGNORE',$v['ldt_sec']);
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    $temp         = "{$v['sku']},\"{$cacheSku[$v['sku']]}\"\t,{$v['su_id']}::{$cacheSu[$v['su_id']]},{$v['ldt_sec']}\r\n";
                    fwrite($fp,$temp);
                }
            }

            if(!empty($this->defs)) {
                $skus = $sus = $cacheSku = $cacheSu = array(); //初始化数组
                foreach($data as $v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    $skus[$v['sku']] = $v['sku'];
                    $sus[$v['su_id']] = $v['su_id'];
                }
                if($temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$skus).'")'),TRUE)){ //无可奈何的写法
                    foreach($temp as &$v){
                        $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                        $cacheSku[$v['sku']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                if($temp = newerpclientapi::getSuppliernameBatch($sus)){ //亲,系统好好设计下呗
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                foreach($data as $v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    if(!isset($cacheSku[$v['sku']])) $cacheSku[$v['sku']] = "";
                    if(!isset($cacheSu[$v['su_id']])) $cacheSu[$v['su_id']] = "";
                    $temp         = "{$v['sku']},\"{$cacheSku[$v['sku']]}\"\t,\"{$v['su_id']}::{$cacheSu[$v['su_id']]}\"\t,{$v['ldt_sec']}\r\n";
                    fwrite($fp,$temp);
                }
            }

            fclose($fp);
        }

        echo $md5;
    }

    public function action_sku_downLoad()
    {
        set_time_limit(0);
        header('Content-Type: application/download'); //下载头
        header('Content-Transfer-Encoding: binary'); //二进制
        header('Content-Disposition: attachment; filename='.iconv('UTF-8','GB18030//IGNORE','供应商SKU最大第二大值交期报表').'.csv'); //文件名
        header('Pragma:no-cache'); //不缓存

        $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$_GET['md5'].'.csv';
        $fp   = fopen($path,'r');
        flock($fp,LOCK_SH); //加共享锁
        while(!feof($fp)){ //读取数据
            echo fread($fp,8192);
        }
        fclose($fp);

        exit;
    }

    //最近采购SKU交期
    public function action_lastPurchaseBuild()
    {
        set_time_limit(0);
        ini_set('memory_limit','600M');
        $_POST['type'] = 2;
        $md5      = md5(join('::',$_POST));
        $path     = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$md5.'.csv';
        $cacheSku = array();
        $cacheSu  = array();
        if(!is_file($path)||date('Y-m-d',$_SERVER['REQUEST_TIME'])!==date('Y-m-d',filemtime($path))){ //缓存失效
            $fp = fopen($path,'a+');
            flock($fp,LOCK_EX); //加独享锁
            ftruncate($fp,0); //清空文件内容

            fwrite($fp,iconv('UTF-8','GB18030//IGNORE','sku,商品名,供应商,最近采购第二大交期')."\r\n");

            $sql = $this->getSelSql($_POST);
            $temp_arr = DB::query(Database::SELECT, $sql)->execute('newerp')->as_array();
            $skus = $su_ids = array();
            foreach($temp_arr as $t) {
                $skus[] = strtoupper(trim(str_replace(" ", "", $t['sku'])));
                $su_ids[] = $t['su_id'];
            }
            $goals = self::getLasted($skus, $su_ids);

            while(tool::eachSql($sql,$data)){
                $skus = $su_ids = array(); //初始化数组
                $flag = 0;
                $data_temp = array();
                foreach($data as &$v){
                    $v['sku'] = strtoupper(trim(str_replace(" ", "", $v['sku'])));
                    if(isset($goals[$v['sku']]) && $goals[$v['sku']] == $v['su_id']) {
                        $flag = 1;
                        $data_temp[] = $v;
                        isset($cacheSku[$v['sku']])||$skus[$v['sku']] = & $v['sku'];
                        isset($cacheSu[$v['su_id']])||$sus[$v['su_id']] = & $v['su_id'];
                    }else{
                        continue;
                    }
                }

                if(!$flag)continue;

                $data = $data_temp;

                if($temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$skus).'")'),TRUE)){ //无可奈何的写法
                    foreach($temp as &$v){
                        $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                        $cacheSku[$v['sku']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                if($temp = newerpclientapi::getSuppliernameBatch($sus)){ //亲,系统好好设计下呗
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                foreach($data as &$v){
                    $v['ldt_sec'] = iconv('UTF-8','GB18030//IGNORE',$v['ldt_sec']);
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    $temp         = "{$v['sku']},\"{$cacheSku[$v['sku']]}\"\t,{$v['su_id']}::{$cacheSu[$v['su_id']]},{$v['ldt_sec']}\r\n";
                    fwrite($fp,$temp);
                }
            }

            if(!empty($this->defs)) {
                $skus = $sus = $cacheSku = $cacheSu = array(); //初始化数组
                foreach($data as $v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    $skus[$v['sku']] = $v['sku'];
                    $sus[$v['su_id']] = $v['su_id'];
                }
                if($temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$skus).'")'),TRUE)){ //无可奈何的写法
                    foreach($temp as &$v){
                        $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                        $cacheSku[$v['sku']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                if($temp = newerpclientapi::getSuppliernameBatch($sus)){ //亲,系统好好设计下呗
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                foreach($data as $v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    if(!isset($cacheSku[$v['sku']])) $cacheSku[$v['sku']] = "";
                    if(!isset($cacheSu[$v['su_id']])) $cacheSu[$v['su_id']] = "";
                    $temp         = "{$v['sku']},\"{$cacheSku[$v['sku']]}\"\t,\"{$v['su_id']}::{$cacheSu[$v['su_id']]}\"\t,{$v['ldt_sec']}\r\n";
                    fwrite($fp,$temp);
                }
            }

            fclose($fp);
        }

        echo $md5;
    }

    public function action_lastPurchase()
    {
        set_time_limit(0);
        header('Content-Type: application/download'); //下载头
        header('Content-Transfer-Encoding: binary'); //二进制
        header('Content-Disposition: attachment; filename='.iconv('UTF-8','GB18030//IGNORE','最近采购供应商第二大交期').'.csv'); //文件名
        header('Pragma:no-cache'); //不缓存

        $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$_GET['md5'].'.csv';
        $fp   = fopen($path,'r');
        flock($fp,LOCK_SH); //加共享锁
        while(!feof($fp)){ //读取数据
            echo fread($fp,8192);
        }
        fclose($fp);

        exit;
    }

    //最近采购SKU交期
    public function action_goMaxMinEveBuild()
    {
        set_time_limit(0);
        $_POST['type'] = 3;
        $md5      = md5(join('::',$_POST));
        $path     = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$md5.'.csv';
        $cacheSku = array();
        $cacheSu  = array();
        if(!is_file($path)||date('Y-m-d',$_SERVER['REQUEST_TIME'])!==date('Y-m-d',filemtime($path))){ //缓存失效
            $fp = fopen($path,'a+');
            flock($fp,LOCK_EX); //加独享锁
            ftruncate($fp,0); //清空文件内容

            fwrite($fp,iconv('UTF-8','GB18030//IGNORE','sku,商品名,供应商,去最大最小平均交期')."\r\n");

            $sql = $this->getSelSql($_POST);
            $sql = str_replace('ldt_ord','ldt_ords',$sql);
            $temp_arr = DB::query(Database::SELECT, $sql)->execute('newerp')->as_array();
            $skus = $su_ids = array();
            foreach($temp_arr as $t) {
                $skus[] = strtoupper(trim(str_replace(" ", "", $t['sku'])));
                $su_ids[] = $t['su_id'];
            }

            $goals = self::getLasted($skus, $su_ids);

            while(tool::eachSql($sql,$data)){
                $skus = $su_ids = array(); //初始化数组
                $flag = 0;
                $data_temp = array();
                foreach($data as &$v){
                    $v['sku'] = strtoupper(trim(str_replace(" ", "", $v['sku'])));
                    if(isset($goals[$v['sku']]) && $goals[$v['sku']] == $v['su_id']) {
                        $flag = 1;
                        $data_temp[] = $v;
                        isset($cacheSku[$v['sku']])||$skus[$v['sku']] = & $v['sku'];
                        isset($cacheSu[$v['su_id']])||$sus[$v['su_id']] = & $v['su_id'];
                    }else{
                        continue;
                    }
                }

                if(!$flag)continue;

                $data = $data_temp;

                if($temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$skus).'")'),TRUE)){ //无可奈何的写法
                    foreach($temp as &$v){
                        $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                        $cacheSku[$v['sku']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                if($temp = newerpclientapi::getSuppliernameBatch($sus)){ //亲,系统好好设计下呗
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                foreach($data as &$v){
                    $v['ldt_sec'] = iconv('UTF-8','GB18030//IGNORE',$v['ldt_sec']);
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    $temp         = "{$v['sku']},\"{$cacheSku[$v['sku']]}\"\t,{$v['su_id']}::{$cacheSu[$v['su_id']]},{$v['ldt_sec']}\r\n";
                    fwrite($fp,$temp);
                }
            }

            if(!empty($this->defs)) {
                $skus = $sus = $cacheSku = $cacheSu = array(); //初始化数组
                foreach($data as $v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    $skus[$v['sku']] = $v['sku'];
                    $sus[$v['su_id']] = $v['su_id'];
                }
                if($temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$skus).'")'),TRUE)){ //无可奈何的写法
                    foreach($temp as &$v){
                        $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                        $cacheSku[$v['sku']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                if($temp = newerpclientapi::getSuppliernameBatch($sus)){ //亲,系统好好设计下呗
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = iconv('UTF-8','GB18030//IGNORE',$v['name']);
                    }
                }

                foreach($data as $v){
                    $v['sku'] = trim(str_replace(" ", "", $v['sku']));
                    if(!isset($cacheSku[$v['sku']])) $cacheSku[$v['sku']] = "";
                    if(!isset($cacheSu[$v['su_id']])) $cacheSu[$v['su_id']] = "";
                    $temp         = "{$v['sku']},\"{$cacheSku[$v['sku']]}\"\t,\"{$v['su_id']}::{$cacheSu[$v['su_id']]}\"\t,{$v['ldt_sec']}\r\n";
                    fwrite($fp,$temp);
                }
            }

            fclose($fp);
        }

        echo $md5;
    }

    public function action_goMaxMinEve()
    {
        set_time_limit(0);
        header('Content-Type: application/download'); //下载头
        header('Content-Transfer-Encoding: binary'); //二进制
        header('Content-Disposition: attachment; filename='.iconv('UTF-8','GB18030//IGNORE','最近采购去最大最小平均供应商交期').'.csv'); //文件名
        header('Pragma:no-cache'); //不缓存

        $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/disk/'.$_GET['md5'].'.csv';
        $fp   = fopen($path,'r');
        flock($fp,LOCK_SH); //加共享锁
        while(!feof($fp)){ //读取数据
            echo fread($fp,8192);
        }
        fclose($fp);

        exit;
    }

    public function getLasted($skus = NULL, $su_ids = NULL) {
        $lp = array();
        if(!empty($skus) && !empty($su_ids)) {
            $lps = DB::select('purchaseorder_details.purchaseorder_id','purchaseorder_details.purchaseorder_id','purchaseorder_details.supplier','purchaseorder_details.sku','purchaseorder_details.quantity','purchaseorder_details.details_date')
                ->from('purchaseorder_details')
                ->join('purchaseorders')
                ->on('purchaseorders.id','=','purchaseorder_details.purchaseorder_id')
                ->where('purchaseorder_details.sku','in',$skus)
                ->where('purchaseorder_details.supplier','in', $su_ids)
                ->where('purchaseorders.status','!=',100)
                ->where('purchaseorder_details.status','!=', 100)
                ->order_by('purchaseorders.id', 'DESC')
                ->execute('newerp')
                ->as_array();

            foreach($lps as $pd){
                if(isset($lp[$pd['sku']]))
                {
                    continue;
                }
                $lp[$pd['sku']] = $pd['supplier'];
            }
        }

        return $lp;
    }


}